/******************************************************************
 * @version      : 1.0
 * @Author       : zhl
 * @Date         : 2023-05-17 13:54:19
 * @LastEditors  : zhl
 * @E-Mail       : zhll168@163.com
 * @Description  : 业务描述
 ******************************************************************/
#ifndef __UPGRADE_DATA_H__
#define __UPGRADE_DATA_H__
#include <unistd.h>
#include <stdint.h>
#include <string>
#include <iostream>
#include <list>

typedef struct _UPGRADE_REQ_DATA{
    int64_t  upgrade_id;
    int64_t  target;
    std::string uri;
    std::string username;
    std::string password;
    
    _UPGRADE_REQ_DATA(){
        upgrade_id = 0;
        this->target = 0;
        this->uri = "";
        username = "admin";
        password = "8848";
    }
    _UPGRADE_REQ_DATA& operator =(const _UPGRADE_REQ_DATA& data){
        if (this != &data)
        {
            upgrade_id = data.upgrade_id;
            target = data.target;
            uri = data.uri;
            username = data.username;
            password = data.password;
        }
        return *this;
    }
}UPGRADE_REQ_DATA;

typedef struct _UPGRADE_REP_DATA{
    int code;
    int64_t upgrade_id;
    std::string msg;
    _UPGRADE_REP_DATA(){
        this->upgrade_id = 0;
        this->code = -1;
        this->msg = "";
    }
    _UPGRADE_REP_DATA& operator =(const _UPGRADE_REP_DATA& data)
    {
        if (this != &data)
        {
            upgrade_id = data.upgrade_id;
            code = data.code;
            msg = data.msg;
        }
        return *this;
    }
}UPGRADE_REP_DATA;

typedef struct _REPORT_UPGRADE_STATE{
    int code;
    int64_t upgrade_id;
    std::string msg;
    _REPORT_UPGRADE_STATE(){
        this->upgrade_id = 0;
        this->code = 0;
        this->msg = "";
    }
    _REPORT_UPGRADE_STATE& operator =(const _REPORT_UPGRADE_STATE& data)
    {
        if (this != &data)
        {
            upgrade_id = data.upgrade_id;
            code = data.code;
            msg = data.msg;
        }
        return *this;
    }
}REPORT_UPGRADE_DATA;

typedef struct _VERSION_DATA{
    std::string ver;
    int code;
    int target;
    _VERSION_DATA(){
        this->ver = "0.0.0";
        this->code = -1;
        this->target = 0;
    }
    _VERSION_DATA& operator =(const _VERSION_DATA& data)
    {
        if (this != &data)
        {
            code = data.code;
            target = data.target;
            ver = data.ver;
        }
        return *this;
    }
}VERSION_DATA;

template<typename T>
struct MSG_DATA_TYPE{
    std::string sn;
    int64_t     command_id;
    std::string command;
    std::string command_type;
    uint64_t    timestamp;
    T data;

    MSG_DATA_TYPE(){
        this->sn = "0.0.0";
        this->command_id = -1;
        this->command = "";
        this->command_type = "NONE";
        this->timestamp = 0;
    }
    MSG_DATA_TYPE& operator =(const MSG_DATA_TYPE& msg){
        if (this != &msg){
            sn = msg.sn;
            command_id = msg.command_id;
            command = msg.command;
            command_type = msg.command_type;
            timestamp = msg.timestamp;
            data = msg.data;
        }
        return *this;
    }
};

typedef struct _MSG_HEADER{
    std::string sn;
    std::string command;
    int64_t     command_id;
    std::string command_type;
    uint64_t    timestamp;
    _MSG_HEADER(){
        sn = "0000000000000000";
        command = "unknown";
        command_id = -1;
        command_type = "UNKNOWN";
        timestamp = 0;
    }
    _MSG_HEADER& operator =(const _MSG_HEADER& data){
        if (this != &data){
            sn = data.sn;
            command = data.command;
            command_id = data.command_id;
            command_type = data.command_type;
            timestamp = data.timestamp;
        }
        return *this;
    }
}MSG_HEADER;

typedef struct _REPORT_LOG_DATA{
    std::string file_name;    //文件名
    std::string file_type;    //文件类型
    std::string content;      //文件类型
    int packet_num;           //当前包含
    int packet_total_num;     //总的包数
    _REPORT_LOG_DATA(){
        file_name = "";
        file_type = "";
        content = "";
        packet_num = 0;
        packet_total_num = 0;
    }
    _REPORT_LOG_DATA& operator=(const _REPORT_LOG_DATA& data){
        if(this != &data){
            file_name = data.file_name;
            file_type = data.file_type;
            content = data.content;
            packet_num = data.packet_num;
            packet_total_num = data.packet_total_num;
        }
        return *this;
    }
}REPORT_LOG_DATA;

typedef struct _GET_LOG_PARAMS{
    int type;
    _GET_LOG_PARAMS(){
        type = -1;
    }
    _GET_LOG_PARAMS& operator=(const _GET_LOG_PARAMS& data){
        if(this != &data){
            type = data.type;
        }
        return *this;
    }
}GET_LOG_PARAMS;

typedef struct _COMMAND_PARAMS{
    std::string cmd;
    _COMMAND_PARAMS& operator =(const _COMMAND_PARAMS& data){
        if (this != &data){
            cmd = data.cmd;
        }
        return *this;
    }
}COMMAND_PARAMS;

typedef struct _COMMAND_RESULT{
    std::string result;
    _COMMAND_RESULT& operator =(const _COMMAND_RESULT& data){
        if (this != &data){
            result = data.result;
        }
        return *this;
    }
}COMMAND_RESULT;
typedef struct MSG_DATA_TYPE<UPGRADE_REQ_DATA> UPGRADE_REQ_MSG_TYPE;
typedef struct MSG_DATA_TYPE<UPGRADE_REP_DATA> UPGRADE_REP_MSG_TYPE;
typedef struct MSG_DATA_TYPE<std::list<VERSION_DATA>> ONLINE_MSG_TYPE;

typedef struct MSG_DATA_TYPE<COMMAND_PARAMS>  EXECUTE_CMD_TYPE;
typedef struct MSG_DATA_TYPE<COMMAND_RESULT>  EXECUTE_CMD_RESULT;
typedef struct MSG_DATA_TYPE<REPORT_LOG_DATA> REPORT_LOG_REQ_OR_REP;
typedef struct MSG_DATA_TYPE<GET_LOG_PARAMS>  GET_LOG_REQ;

#endif /* __UPGRADE_DATA_H__ */